package com.vmj.instructions.stores;

import com.vmj.heap.ArrayObject;
import com.vmj.heap.VMObject;
import com.vmj.instructions.base.CheckUtils;
import com.vmj.instructions.base.NoOperandsInstruction;
import com.vmj.rtda.Frame;
import com.vmj.rtda.OperandStack;

/**
 * Created by yangshoujun on 2017/9/9 下午1:59.
 */
public class BAStore extends NoOperandsInstruction {
    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        byte val = (byte) stack.popInt();
        int index = stack.popInt();
        VMObject arrRef = stack.popRef();
        CheckUtils.checkNotNull(arrRef);
        byte[] data = ArrayObject.getBytes(arrRef);
        CheckUtils.checkIndex(data.length, index);
        data[index] = val;
    }
}
